package com.battle.pojo.enums.resource;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import nirvana.core.domains.enums.Enums;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Joseph.Li
 * @author joseph.li@king-v.com
 * Created in 2022-06-17 0:26
 * <p>
 * 资源类型
 */
@Getter
@AllArgsConstructor
public enum ResourceTypeEnum implements Enums {

    MODEL(0,"模块"),
    MENU(1, "菜单"),
    PAGE(2, "页面"),
    BUTTON(3, "按钮"),
    INTERFACE(4, "接口");

    @JsonValue
    @EnumValue
    private Integer id;
    private String name;

    public static ResourceTypeEnum getById(Integer id) {
        for (ResourceTypeEnum value : ResourceTypeEnum.values()) {
            if (value.getId().equals(id)) {
                return value;
            }
        }
        return null;
    }

    public static ArrayList<ResourceTypeEnum> getList(List<Integer> typeList) {
        ArrayList<ResourceTypeEnum> list = new ArrayList<>();
        if (typeList != null) {
            for (Integer type : typeList) {
                list.add(ResourceTypeEnum.getById(type));
            }
        } else {
            Collections.addAll(list, ResourceTypeEnum.values());
        }
        return list;
    }

    public static ArrayList<ResourceTypeEnum> getList() {
        return getList(null);
    }
}
